PROJECT:=go-admin

mod:
	go mod tidy

.PHONY: build
build:
	GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.version=${VERSION} -X main.gitRev=$(GITREV) -X main.buildTime=$(BUILDTIME)" -o tw-education main.go

build-linux:
	GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.version=${VERSION} -X main.gitRev=$(GITREV) -X main.buildTime=$(BUILDTIME)" -o tw-education main.go

build-linux-prod:
	GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.version=${VERSION} -X main.gitRev=$(GITREV) -X main.buildTime=$(BUILDTIME)" -o tw-education-prod main.go

build-sqlite:
	go build -tags sqlite3 -o tw-education main.go
#.PHONY: test
#test:
#	go test -v ./... -cover

.PHONY: docker-dev
docker-dev: build
	docker build . -f ./Dockerfile-dev -t tw/education:latest

.PHONY: docker-test
docker-test:mod build-linux
	docker build . -f ./Dockerfile-test -t tw/education:latest

.PHONY: docker-prod
docker-prod: build-linux-prod
	docker build . -t tw/education-prod:latest

tag:
# 	docker tag tw/education-prod:latest registry.cn-chengdu.aliyuncs.com/ronghaichuan-k8s-master/tw-education:latest
	docker tag tw/education-prod:latest registry.cn-chengdu.aliyuncs.com/ronghaichuan-k8s-master/tw-education-prod:latest

push:
# 	docker push registry.cn-chengdu.aliyuncs.com/ronghaichuan-k8s-master/tw-education:latest
	docker push registry.cn-chengdu.aliyuncs.com/ronghaichuan-k8s-master/tw-education-prod:latest

network:
	docker network create  education

up-base:
	cd docker && docker-compose -f base.yml up -d

down-base:
	cd docker && docker-compose -f base.yml down

up-tw-dev:
	cd docker && docker-compose -f docker-compose-dev.yml up -d

down-tw-dev:
	cd docker && docker-compose -f docker-compose-dev.yml down

up-tw-test:
	cd docker && docker-compose -f docker-compose-test.yml up -d

down-tw-test:
	cd docker && docker-compose -f docker-compose-test.yml down

up-tw-prod:
	cd docker && docker-compose  --project-name tw-prod up -d

down-tw-prod:
	cd docker && docker-compose  --project-name tw-prod down

up-dev: up-base up-tw-dev

down-dev: down-base down-tw-dev

up-test: up-base

down-test: down-base down-tw-test

up-prod: up-base up-tw-prod

down-prod: down-base down-tw-prod


del-migrate:
	go run migrate.go

init-db: del-migrate
	./tw-education migrate -c=./config/settings.dev.yml

init-test-docker-db: del-migrate
	./tw-education migrate -c=./config/settings.test.yml && rm -rf tw-education

init-prod-docker-db: del-migrate
	./tw-education-prod migrate -c=./config/settings.yml
run: mod build init-db
	./tw-education server -c=./config/settings.dev.yml


localRun:
	go run main.go server -c=./config/settings.dev.yml







